package frame;

import global.Const;
import listen.MyListener;
import panel.login.LogInPanel;
import panel.login.SignUpPanel;
import panel.common.BackGround;
import panel.login.Index;
import windows.LoadingDialog;
import windows.MessageDialog;

import javax.swing.*;

public class Login extends JFrame {

    // 窗口
    public static LogInPanel logInPanel = new LogInPanel();
    public static Index index = new Index();
    public static SignUpPanel signUpPanel = new SignUpPanel();
    public static MessageDialog messageDialog = new MessageDialog();
    public static LoadingDialog loadingDialog = new LoadingDialog();

//    public Login() {
//        init();
//    }

    private void init() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(Const.FRAME_WIDTH, Const.FRAME_HEIGHT);
        setLocationRelativeTo(null);
        setTitle(Const.TITLE);
        setResizable(false);
        setLayout(null);

        // 背景
        BackGround backGround = new BackGround("src/main/resources/image/login/background.png");

        // 从上层到下层添加组件
        add(loadingDialog);
        add(messageDialog);
        add(signUpPanel);
        add(logInPanel);
        add(index);
        add(backGround);
    }

    public void open() {
        init();
        index.open();
        setVisible(true);
        repaint();
        System.out.print("启动成功\n");
    }

    // 全局字体抗锯齿，必须在初始化 JFrame 之前调用！
    static void enableAntiAliasing() {
        System.setProperty("awt.useSystemAAFontSettings", "on");
        System.setProperty("swing.aatext", "true");
    }

    public void close() {
        dispose();
    }
}
